package com.sc.nft.req.points;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sc.nft.enums.UserPointsOperateEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author JYT
 * @create 2024/5/13 15:39
 */
@Data
public class PointsReq {

    /**
     * 微信小程序用户id
     */
    @ApiModelProperty(value = "微信小程序用户id")
    private Long miniUserId;
    /**
     * 操作积分
     */
    @ApiModelProperty(value = "操作积分")
    private BigDecimal points;
    /**
     * 操作类型
     */
    @ApiModelProperty(value = "操作类型 BUY_SELF  消费-自购,BUY_FRIEND  消费-好友下单,INVITE_REGISTER  邀请-好友注册,OFFICIAL_GIFT  官方赠送,OFFICIAL_TAKE_OUT  官方扣除,EXCHANGE_GOODS  兑换-兑换卡,REFUND_SELF  退款-自购,REFUND_FRIEND  退款-好友下单,EXPIRE  积分过期")
    private UserPointsOperateEnum operateType;
    /**
     * 操作订单
     */
    @ApiModelProperty(value = "操作订单")
    private Long orderId;
    /**
     * 支付金额
     */
    @ApiModelProperty(value = "支付金额")
    private BigDecimal orderPrice;
    /**
     * 邀请用户id
     */
    @ApiModelProperty(value = "邀请用户id")
    private Long inviteUserId;
    /**
     * 创建时间
     */
    @ApiModelProperty(value = "创建时间")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    /**
     * 兑换卡id
     */
    @ApiModelProperty(value = "兑换卡id")
    private Long redeemCardId;

    @ApiModelProperty(value = "退款金额")
    private BigDecimal orderRefundPrice;

    /**
     * 分享的用户id
     */
    @ApiModelProperty(value = "分享的用户id")
    private Long shareUserId;


    /**
     * 下单发放积分
     *
     * @param miniUserId
     * @param shareUserId
     * @param orderId
     * @param orderPrice
     * @param createTime
     * @param points
     * @return
     */
    public static PointsReq buildBuySelfAndFriends(Long miniUserId, Long shareUserId, Long orderId, BigDecimal orderPrice, Date createTime, BigDecimal points) {
        PointsReq pointsReq = new PointsReq();
        pointsReq.setOperateType(UserPointsOperateEnum.BUY_SELF);
        pointsReq.setMiniUserId(miniUserId);
        pointsReq.setShareUserId(shareUserId);
        pointsReq.setPoints(points);
        pointsReq.setOrderId(orderId);
        pointsReq.setOrderPrice(orderPrice);
        pointsReq.setCreateTime(createTime);
        return pointsReq;
    }

    /**
     * 收货解冻积分
     *
     * @param orderId
     * @return
     */
    public static PointsReq buildBuyUnLock(Long orderId) {
        PointsReq pointsReq = new PointsReq();
        pointsReq.setOrderId(orderId);
        return pointsReq;
    }

    /**
     * 退款减积分
     *
     * @param miniUserId
     * @param orderId
     * @param orderPrice
     * @param orderRefundPrice
     * @return
     */

    public static PointsReq buildRefundSelfAndFriend(Long miniUserId, Long shareUserId, Long orderId, BigDecimal orderPrice, BigDecimal orderRefundPrice) {
        PointsReq pointsReq = new PointsReq();
        pointsReq.setOperateType(UserPointsOperateEnum.REFUND_SELF);
        pointsReq.setMiniUserId(miniUserId);
        pointsReq.setOrderId(orderId);
        pointsReq.setOrderPrice(orderPrice);
        pointsReq.setOrderRefundPrice(orderRefundPrice);
        pointsReq.setShareUserId(shareUserId);
        return pointsReq;
    }

}
